﻿@using ECG.WebUI.CustomHelpers
@model List<ECG.Common.ProductListByPromotionPageDto>
@{
    var t = (string)ViewBag.type ?? "mn";
    var chkPaging = (bool)ViewBag.chkPagging;
}

<input type="hidden" name="hidItemRecord_@ViewBag.Page" value="@ViewBag.ItemRecord" />
<input type="hidden" name="hidCurrentPage" value="@ViewBag.Page" />
<div class="totalP clearfix">
    <div class="totalText fl">
        <h1>Có <strong id="totalRecord">@ViewBag.TotalRecord</strong> sản phẩm khuyến mại</h1>
    </div>
    <div class="totalPSort fr" idata="@t">
        <a href="javascript:void(0);" class="p-new p-ac-sort" idata="mn">Mới nhất</a>
        <a href="javascript:void(0);" class="p-buy" idata="bm">Bán chạy</a>
        <a href="javascript:void(0);" class="p-price" idata="pb">Giá tốt nhất</a>
    </div>
</div>
@{
    if (Model.Any())
    {
        var count = 0;
        if (chkPaging)
        {
            <div class="clearfix" style="width: 100%;">
                <div class="bb_pagging">
                    @Html.PageLinksOnProductListCatePage((ECG.WebUI.Models.PageInfo)ViewBag.PageInfo, i => Url.Action("home", "PromotionPage", new { page = i, sortdrop = ViewBag.Fillter, catefil = ViewBag.CateFill }))
                </div>
            </div>
        }

        <ul class="ListP ul clearfix">
            @foreach (var item in Model)
            {
                count++;
                var classEnd = "";
                if (count % 4 == 0)
                {
                    classEnd = "class='ln'";
                }
                var pDetailLink = Url.Action("Index", "ProductDetail", new { productId = item.Id, productName = ECG.Utility.StringUtil.RemoveSpecialCharactersVn(item.Name) });
                <li @Html.Raw(classEnd)>
                    <div class="img">
                        @if (item.PromotionPrice > 0)
                        {
                            <i>@item.DiscountPercentage.ToString("#.#")<b>%</b></i>
                        }

                        <a href="@pDetailLink">
                            <img src="@item.ImagePath.ImagePathThumb(275, 275)" alt="@item.Name" width="275" height="275" class="lzLoading" />
                        </a>
                        <div class="pRate">
                            @{
                        string StarPercent = "0";
                        if (item.AverageRate > 0)
                        {
                            StarPercent = (Convert.ToDouble(item.AverageRate) * 100 / 5).ToString("#.#").Replace(',', '.');
                        }
                            }
                            <p><span class="itm-ratStars inlineBlocka"><span style="width: @StarPercent%;" class="itm-ratStars itm-ratRating"></span></span></p>
                        </div>
                    </div>
                    <div class="info">
                        <p class="pName">
                            <a href="@pDetailLink" class="aName">
                                @item.Name
                            </a>
                        </p>
                        @if (item.PromotionPrice > 0)
                        {
                            <p style="margin-top: 5px;">
                                <span class="priceItem">@item.PromotionPrice.ToString("##,###,###") đ</span>
                                <span class="priceOldItem">@item.Price.ToString("##,###,###") đ</span>
                            </p>
                        }
                        else
                        {
                            <p style="margin-top: 5px;">
                                <span class="priceItem">@item.Price.ToString("##,###,###") đ</span>
                            </p>
                        }
                        @if (item.TotalOrder > 0)
                        {
                            <p class="cusBuy">
                                <i><strong>@item.TotalOrder</strong> người đã mua</i>
                            </p>
                        }
                        else
                        {
                            <p class="cusBuy">&nbsp;</p>
                        }
                    </div>
                </li>
            }
        </ul>
        if (chkPaging)
        {
            <div class="clearfix" style="width: 100%;">
                <div class="bb_pagging ">
                    @Html.PageLinksOnProductListCatePage((ECG.WebUI.Models.PageInfo)ViewBag.PageInfo, i => Url.Action("home", "PromotionPage", new { page = i, sortdrop = ViewBag.Fillter, catefil = ViewBag.CateFill }))
                </div>
            </div>
        }
    }
}
